# -*- coding: utf-8 -*-

import tornado.ioloop
import tornado.web
import upload as upload
import os
import globalvar as gl
import time
class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.set_header("Access-Control-Allow-Origin", "*")
        self.set_header("Access-Control-Allow-Headers", "x-requested-with")
        self.set_header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS')
        self.render("./static/index.html")


def make_app():
    return tornado.web.Application([
        (r"/", MainHandler),
        (r"/upload",    upload.UploadHandler)
    ],
        static_path=os.path.join(os.path.dirname(__file__), "static")
    )


if __name__ == "__main__":
    gl._init()
    gl.set_value("runningtime", time.time())
#     current_path = os.path.dirname(__file__)
    app = make_app()
    app.listen(8080)
    print("server start at port 8080")
    tornado.ioloop.IOLoop.current().start()
